package by.gravity.common;

import java.lang.reflect.Field;

import android.app.Application;
import android.view.ViewConfiguration;
import by.gravity.common.http.HttpClient;
import by.gravity.common.utils.ContextHolder;

public class CoreApplication extends Application {

	private HttpClient httpClient;

	@Override
	public void onCreate() {
		super.onCreate();
		showMenuButtonOnActionBar();
		httpClient = new HttpClient(getApplicationContext());
		ContextHolder.setContext(getApplicationContext());

	}

	private void showMenuButtonOnActionBar() {
		try {
			ViewConfiguration config = ViewConfiguration.get(this);
			Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
			if (menuKeyField != null) {
				menuKeyField.setAccessible(true);
				menuKeyField.setBoolean(config, false);
			}
		} catch (Exception ex) {
		}
	}

	@Override
	public Object getSystemService(String name) {
		if (name.equals(HttpClient.HTTP_CLIENT)) {
			return httpClient;
		}
		return super.getSystemService(name);
	}
}
